using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using System.Transactions;
using GC2.Entities.Admin;
using GC2.ExceptionHandler.Services;
using GC2.DataAccess.DAAdmin;

namespace GC2.Bussines.BMAdmin
{
    public class BMTareas
    {
        public BMTareas(string coneccion) 
        {
            this.Connection = coneccion;
        }

        private string connection = "";
        public string Connection
        {
            get { return connection; }
            set { connection = value; }
        }

        private Tareas oTareas = new Tareas();
        private List<Tareas> listaTareas = new List<Tareas>();
        private DATareas daTareas = new DATareas();

        #region BMTareasGetAll
        public List<Tareas> BMTareasGetAll()
        {
            try
            {
                listaTareas = daTareas.DATareasGetAll(connection);
                return listaTareas;
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion

        #region BMTareasInsert
        public void BMTareasInsert(Tareas tarea)
        {
            try
            {
                oTareas = daTareas.DATareasGetLast(connection);
                oTareas.Id_Tarea++;
              
                daTareas.DATareasInsert(connection, tarea);
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion

        #region BMTareasUpdate
        public void BMTareasUpdate(Tareas tarea)
        {
            try
            {
                daTareas.DATareasUpdate(connection, tarea);
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion

        #region BMTareasGetLast
        public Tareas BMTareasGetLast()
        {
            try
            {
                oTareas = daTareas.DATareasGetLast(connection);
                return oTareas;
            }
            catch (Exception ex)
            {
                ExceptionBM exNew = new ExceptionBM();
                throw new System.Exception(exNew.exBM(ex.ToString()).ToString());
            }
        }
        #endregion
    }
}
